package com.wecan.components.sms.config;

import com.wecan.base.constants.PropertyConstants;
import com.wecan.components.sms.controller.SMSController;
import com.wecan.components.sms.properties.AliSMSProperties;
import com.wecan.components.sms.properties.TencentSMSProperties;
import com.wecan.components.sms.service.SMSService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @Author liuzhihao
 * @Date 2022.02.16
 * @Version ${version}
 * @Description ${description}
 */
@Configuration
@EnableConfigurationProperties({AliSMSProperties.class, TencentSMSProperties.class})
@Slf4j
public class SMSConfig {

    @PostConstruct
    public void postConstruct() {
        log.info("[APP] |- 初始化APP短信服务");
    }

    @Bean
    public SMSService smsService() {
        return new SMSService();
    }

    @Bean
    @ConditionalOnBean(SMSService.class)
    public SMSController smsController() {
        log.info("[APP] |- 初始化短信web服务");
        return new SMSController();
    }
}
